<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="canvas" width="300" heigth="200"></canvas>
    <script>
        function downloadURI(uri, name) {
            let link = document.createElement("a");
            link.download = name;
            link.href = uri;
            link.click()
        }

        let canvas = document.getElementById("canvas");
        let cxt = canvas.getContext("2d");
        cxt.fillStyle = "red";
        cxt.rect(0, 0, canvas.width, canvas.height);
        cxt.fill();

        let dataURL = canvas.toDataURL();
        downloadURI(dataURL, "hello")
    </script>
</body>

</html>